# 字符串常用api
# str = "nihao py java"
# print(str.capitalize())
# print(str.endswith("a"))
# print(str.startswith("a"))
# print(str.__contains__("a"))
# print(str.split("a"))
# print(str.count("a", 0, str.__len__()))
# print(str.find("hao"))
# print(str.join(","))
# print(str[0:2])

# 列表常用操作
# list1 = ["nihao", "py", "js", "java"]
# for index in range(len(list1)):
#     print(index)
#     print(list1[index])

# list1[0] = "不好"
# print(list1)
# print(list1[0:2])
# del list1[3]
# print(list1)
# list2 = [1, 2, 3, 4]
# print(list1 + list2)
# print(max(list2))
# print(max(list1))
# print(list1[0].__hash__())
# print(len(list1))
#
# list1.append("哈哈")
# print(list1)
# print(list1.count("js"))
# list1.extend(list2)
# print(list1)
# print(list1.index(1))
# list1.insert(0, "xx")
# print(list1)
#
# list1.pop()
# print(list1)
# list1.pop(2)
# print(list1)
#
# list1.remove("js")
# print(list1)
# list1.reverse()
# print(list1)
#
# # list1.clear()
# # print(list1)
# list__copy = list1.copy()
# print("copy", list__copy)
# list1[0] = 999
# print(list1)
# print(list__copy)

# 元祖 不可变 略

# 字典
# dict = {'Name': 'Runoob', 'Age': 7, 'Class': 'First'}
# dict['hobby'] = "lol"
# print(dict)
# if 'hobby' in dict:
#     print(dict['hobby'])
# dict_copy = dict.copy()
# print(id(dict))
# print(id(dict_copy))
#
# dict['hobby'] = 'dnf'
# print(dict)
# print(dict_copy)
#
# keys = dict.keys()
# for key in keys:
#     print(dict[key])
#
# pop = dict.pop('hobby')
# print(pop)
# print(dict)
# print("===================")
# popitem = dict.popitem()
# print(popitem)
# print(dict)
#
# get = dict.get("Name")
# print(get)

# 集合 无序的不重复元素序列
# 数据类型 容器 循环  异常 面向对象  导入

# set = {"dnf", "lol", "cf", "kafka"}
# set.add("csgo")
# print(set)
# # set.remove("aaa")
# set.discard("aaa")
# print(set)
# set2 = {"js", "java", "py", "kafka"}
#
# difference = set.difference(set2)
# print(difference)

# if
# while True:
#     num = int(input("请输入一个整数\n"))
#     if num % 2 == 0:
#         print(num, "是偶数")
#         if num % 3 == 0:
#             print(num, "是 2 和 3 的公倍数")

# count = 0
# while count < 5:
#     print(count, " 小于 5")
#     count = count + 1
# else:
#     print(count, " 大于或等于 5")


# for i in range(0, 10, 3):
#     print(i)
#
# for letter in 'Runoob':  # 第一个实例
#     if letter == 'b':
#         break
#     print('当前字母为 :', letter)
#
# var = 10  # 第二个实例
# while var > 0:
#     print('当期变量值为 :', var)
#     var -= 1
#     if var == 5:
#         break

# for n in range(2, 10):
#     for x in range(2, n):
#         if n % x == 0:
#             print(n, '等于', x, '*', n // x)
#             break
#     else:
#         # 循环中没有找到元素
#         print(n, ' 是质数')

# while 和 for 都可以有else

# pass
# for letter in 'Runoob':
#     if letter == 'o':
#         pass
#         print('执行 pass 块')
#     print('当前字母 :', letter)

# 迭代器
# list = [1, 2, 3, 4, 5, 6]
# 创建一个迭代器
# it = iter(list)
# for item in it:
#     print(item)
# for a in list:
#     print(a)


# 函数
#
# def hello():
#     print("hallo")
#
#
# hello()
#
#
# def add(n1, n2):
#     return n1 + n2
#
#
# result = add(1, 2)
# print(result)

# 参数传递 和java一样
# def funcA(a):
#     a += 1
#     print("对a做了+1")
#
#
# def funcB(dict):
#     dict['name'] = 'cxs'
#     print("对dict的name做了修改")
#
#
# a = 10
# funcA(a)
# print(a)
#
# dict = {"name": "xjw", "age": 22}
# funcB(dict)
# print(dict)


# def funcA(name):
#     print(name)
#
#
# funcA(name='cxs')
#
#
# def funcB(name, age):
#     print(name, age)
#
#
# name = "abc"
# age = "444"
# funcB(age=age, name=name)


# def funcA(name, age=66):
#     print(name, age)
#
#
# funcA(name="cxs", age=99)


# 一个*表示元祖类型
# def funcA(name, *a1):
#     print(name)
#     print(a1)
#
#
# funcA("cxs", 1, 2, 3)


# 两个** 表示字典类型
# def funcA(name, **a1):
#     print(name)
#     print(a1)
#
#
# funcA("cxs", a=1, b=2)

# 单独使用*时 后面还需要加一个参数
# def funcA(name, *, b):
#     print(name)
#     print(b)
#
#
# funcA("cxs", b=1)

# lambda 表达式写法
# sum = lambda a1, a2: a1 + a2
#
# print(sum(10, 20))

# def funcA(a, b):
#     return a + b
#
#
# def funcB():
#     a = 10
#     b = 20
#     c = a + b
#
#
# result = funcA(10, 11)
# print(result)
#
# b = funcB()
# print(b)

# 数据结构使用

# 列表当栈使用  FILO
# list = []
# list.append("a")
# list.append("b")
# list.append("c")
#
# print(list)
#
# print(list.pop())
# print(list.pop())
# print(list.pop())

# 列表当队列使用 FIFO
# from _collections import deque
#
# queue = deque(["a", "b", "c"])
# queue.append("d")
#
# print(queue)
# while len(queue) > 0:
#     print(queue.popleft())
# else:
#     print("没有了")

# 列表推导公式
# list = [1, 2, 3]
#
# res = [3 * x for x in list]
# print(res)
#
# del list[1:2]
# print(list)

# 列表 []
# 元祖 ()
# 集合 {}
# 字典 {k:v}
#
# list = ["a", "b", "c", "d"]
#
# res = [x for x in list if x not in ("a", "b")]
# print(res)

# knights = {'gallahad': [{"name": "cxs", "age": 15}, {"name": "xjw", "age": 18}], 'robin': 'the brave'}
# for k, v in knights.items():
#     if type(v) == list:
#         for it in v:
#             print(k, it)
#     else:
#         print(k, v)
#


# questions = ['name', 'quest', 'favorite color']
# answers = ['lancelot', 'the holy grail', 'blue']
#
# for q, a in zip(questions, answers):
#     print(q, ":", a)

# 输出格式化
# import time
#
# print("当前时间为:{},id为:{}".format(time.localtime(), 1))
# print("当前时间为:{},id为:{id}".format(time.localtime(), id=1))

# 文件file操作

# txt = open("D:\\a.txt", "a+")
# txt.write("我是java")
# txt.write("\n")
# txt.write("我是js")
# txt.close()
#
# t = open("D:\\a.txt", "r")
# print(t.readline())
# print(t.readlines())
# t.close()

# for line in t:
#     print(line, end='')
#
# t.close()

# with open("D:\\a.txt", "r") as t:
#     for line in t:
#         print(line, end='')
# t.close()

# import shutil
#
# # 文件拷贝
# shutil.copy("D:\\a.txt", "D:\\b.txt")


# 序列化和反序列化
import pickle

# data1 = {'a': [1, 2.0, 3, 4 + 6j],
#          'b': ('string', u'Unicode string'),
#          'c': None}
#
# output = open('D:\\xuliehua.txt', 'wb')
#
# pickle.dump(data1, output)
#
# output.close()

# 使用pickle模块从文件中重构python对象
# pkl_file = open('D:\\xuliehua.txt', 'rb')
#
# data1 = pickle.load(pkl_file)
# print(data1)

# os指令
import os


# os.remove("D:\\xuliehua.txt")

# os.rmdir("D:\\aaa")

# 异常
# try:
#     print(10 / 0)
# except ZeroDivisionError:
#     print("x")


# def this_fails():
#     x = 1 / 0
#
#
# try:
#     this_fails()
# except (OSError, ZeroDivisionError) as err:
#     print("错了", err)
# finally:
#     print("来了")

# raise 抛异常
# try:
#     raise NameError('HiThere')
# except NameError:
#     print('An exception flew by!')
#     raise  # 接着抛

# 自定义异常
# class MyError(Exception):
#     def __init__(self, value):
#         self.value = value
#
#     def __str__(self):
#         return repr(self.value)
#
#
# try:
#     raise MyError("我自己的异常")
# except MyError as e:
#     print(e)
